<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
    <%--<link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/css/H-ui.min.css">--%>
    <link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/css/H-ui.admin.css">
    <link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/style.css">
    <script type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.3&key=e392de55be62b195115e32b97043a1bd&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
    <script type="text/javascript" src="${ctx}/appjs/member/member/membergain.js"></script>
    <style>
        th,td {
            border-right: 1px solid #eee;
        }
        .rowAddDelBtn {
            line-height: 19.5px;
            margin: 2px;
            color: white;
            width: 20px;
            height: 20px;
            border-radius: 10px;
            border: none;
            font-size: 15px;
            display: inline-block;
        }
        #bableBody tr:first-child .rowDelBtn {
            display: none;
        }
        #chargeHandselBody tr:first-child .rowDelBtn {
            display: none;
        }
    </style>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">会员管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>会员权益</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>编辑会员权益</strong>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a href="javascript:window.history.back()"><i class="fa fa-times"></i> 返回</a>' +
            '</li>' +
            '</ol>';
    });
</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">编辑会员权益</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="frmMemberGain">
                        <span th:text="${childInfo}" style="display: none" id="childInfoId"></span>
                        <input type="hidden" id="gainTypeId" value="${settingInfo.gainType}">
                        <input type="hidden" id="memberGainId" name="memberGainId" value="${settingInfo.memberGainId}">
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">权益名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="gainName" name="gainName"
                                value="${settingInfo.gainName}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">所属会员等级：</label>
                            <div class="col-sm-8">
                                <select id="memberLevel" name="memberLevel" class="form-control" placeholder="所属会员等级">
                                    <c:forEach items="${parLevels}" var="bean">
                                        <option value="${bean.memberLevel}"
                                                <c:if test="${bean.memberLevel == settingInfo.memberLevel}">selected</c:if>
                                        >${bean.memberLevel}
                                        </option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">会员子等级：</label>
                            <div class="col-sm-8">
                                <select id="levelSub" name="levelSub" class="form-control" placeholder="请选择会员子等级">
                                    <c:forEach items="${levels}" var="bean">
                                        <option value="${bean.levelSub}"
                                                <c:if test="${bean.levelSub == settingInfo.levelSub}">selected</c:if>
                                        >${bean.levelSub}
                                        </option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">会员标识图标：</label>
                            <div class="col-sm-8">
                                <div>
                                   <%-- <img id="gainLogo" src="${ctx}/statics/img/upload-img.png"
                                         style="position: relative" width="155px" height="120px">
                                    <input type="file" id="file1" name="file1"/>--%>
                                    <c:choose>
                                        <c:when test="${settingInfo.gainLogo!=null && settingInfo.gainLogo!=''}">
                                            <div id="">
                                                <img id="gainLogo" src="${settingInfo.gainLogo}"
                                                     width="155px" height="120px">
                                                <input type="file" id="file1" name="file1"/>
                                            </div>
                                        </c:when>
                                        <c:otherwise>
                                            <div id="">
                                                <img id="gainLogo" src="${ctx}/statics/img/upload-img.png"
                                                     style="position: relative" width="155px" height="120px">
                                                <input type="file" id="file1" name="file1"/>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">权益类型：</label>
                            <div class="col-sm-4">
                                <input type="radio"   name="gainType" value="0"  onchange="typeChange(this,'0')"
                                       <c:if test="${settingInfo.gainType eq '0'}">checked</c:if>
                                >充值消费折扣
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-4">
                                <input type="radio"  name="gainType" value="1" onchange="typeChange(this,'1')"
                                       <c:if test="${settingInfo.gainType eq '1'}">checked</c:if>>充值赠送金额
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-4">
                                <input type="radio"  name="gainType" value="2" onchange="typeChange(this,'2')"
                                       <c:if test="${settingInfo.gainType eq '2'}">checked</c:if>>生日礼遇
                            </div>
                        </div>
                        <%--<div class="form-group row" id="consumeInputId">
                            <label class="col-sm-3 col-form-label text-right">退款再充值规则：</label>
                                <div style="display:inline" class="col-sm-8 col-sm-8" >
                                    <span class="col-sm-2  col-form-label text-left" >退款</span>
                                    <input type="text" id="refundCountTarget" name="refundCountTarget"  style="width: 10%; border-bottom: 2px solid #666;"
                                    value="${settingInfo.refundCountTarget}">
                                    <span class="col-sm-2  col-form-label text-left">次后,再充值消费无折扣</span></div>
                        </div>
                        <div class="form-group row" id="handselInputId" style="display:none;">
                            <label class="col-sm-3 col-form-label text-right">退款再充值规则：</label></br>
                            <div class="col-sm-8 col-sm-8" >
                                <span class="col-sm-2  col-form-label text-left" >退款</span>
                                <input type="text" id="refundUnhandsel" name="refundUnhandsel"  style="width: 10%; border-bottom: 2px solid #666;"
                                       value="${settingInfo.refundUnhandsel}">
                                <span class="col-sm-2  col-form-label text-left">次后,再充值不赠送权益金</span>
                            </div>
                        </div>--%>
                        <div class="form-group row" id="brithdayId" style="display:none;">
                            <label class="col-sm-3 col-form-label text-right"> </label></br>
                            <div class="col-sm-8 col-sm-8" >
                                <select  name="ticketTypeId"  id="ticketTypeId" class="form-control" placeholder="选择卡券" lay-search="">
                                    <option value="" selected="selected">请选择</option>
                                    <c:forEach items="${ticketInfos}" var="info">
                                        <option value="${info.ticketTypeId}"  <c:if test="${info.ticketTypeId eq settingInfo.ticketTypeId}">selected</c:if> >
                                                ${info.ticketName}|${info.discountTypeName}|${info.userTypeName}|${info.discountDesc}
                                        </option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">是否默认：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="isDefault" id="isDefault">
                                    <option value="0"  <c:if test="${settingInfo.isDefault eq '0'}">selected</c:if>>否</option>
                                    <option value="1"  <c:if test="${settingInfo.isDefault eq '1'}">selected</c:if>>是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">权益说明：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="gainExplain" name="gainExplain"
                                       value="${settingInfo.gainExplain}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">排序：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="sort" name="sort"
                                       value="${settingInfo.sort}">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="status" id="status">
                                    <option value="0"  <c:if test="${settingInfo.status eq '0'}">selected</c:if>>启用</option>
                                    <option value="1"  <c:if test="${settingInfo.status eq '1'}">selected</c:if>>停用</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-3 col-sm-offset-8 text-right">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function typeChange(_val,_index) {
        if (_index == 2) {
            $("#brithdayId").show();
            $("#consumeInputId").hide();
            $("#handselInputId").hide();
            $("#refundCountTarget").val("");
            $("#refundUnhandsel").val("");
        } else {
            if (_index == 0) {
                $("#consumeInputId").show();
                $("#brithdayId").hide();
                $("#handselInputId").hide();
                $("#refundUnhandsel").val("");
                $("#ticketTypeId").val("");
            } else {
                $("#handselInputId").show();
                $("#brithdayId").hide();
                $("#consumeInputId").hide();
                $("#refundCountTarget").val("");
                $("#ticketTypeId").val("");
            }
        }
    }


    $("#file1").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#gainLogo").attr("src", objUrl);
        }
    });

    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) {
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }
</script>

</body>
</html>
<script>

    addMemberGain.init();
</script>
